package frontend.pages.admin.workdetail;

import backend.model.admin.WorkDetail;
import backend.service.admin.WorkDetailService;
import frontend.core.TimeTrackingWebApplication;
import frontend.model.admin.WorkDetailUIModel;
import frontend.pages.admin.base.AbstractManagingPage;
import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.markup.html.panel.Panel;
import org.wicketstuff.annotation.mount.MountPath;

import java.util.List;

import static shared.other.UserRolesDefinition.ADMIN_ROLE_KEY;
import static shared.other.UserRolesDefinition.FOREMAN_ROLE_KEY;

@MountPath("workDetail")
@AuthorizeInstantiation(value = {FOREMAN_ROLE_KEY, ADMIN_ROLE_KEY})
public class WorkDetailManagingPage extends AbstractManagingPage<WorkDetail> {

	public WorkDetailManagingPage() {
		super("pages.admin.workDetail.title", "contextualHelp.admin.workDetail.text");
	}

    @Override
    protected String getAddPanelTitleKey() {
        return "pages.admin.workDetail.add.title";
    }

    @Override
    protected String getEditPanelTitleKey() {
        return "pages.admin.workDetail.edit.title";
    }

    @Override
    protected String getNoSelectionMessageKey() {
        return "pages.admin.workDetail.edit.noSelection";
    }

    @Override
    protected Panel getAddPanel(String panelId) {
        return new WorkDetailPanel(panelId, getPageParameters(), new WorkDetailUIModel());
    }

    @Override
    protected Panel getEditPanel(String panelId, WorkDetail workDetail) {
        getPageParameters().clearNamed();
        return new WorkDetailPanel(panelId, null, new WorkDetailUIModel(workDetail));
    }

    @Override
    public List<WorkDetail> loadAvailableEntities() {
        WorkDetailService workDetailService = TimeTrackingWebApplication.getService(WorkDetailService.class);
        return workDetailService.loadAllWorkDetails();
    }
}
